import React, {useState, useEffect} from 'react'
// import moment from 'moment'
// import 'moment/locale/zh-cn'
// moment.locale('zh-cn')

let timer = null

function TimeTitle(){
    const [time, setTime] = useState('')
    
    useEffect(() => {
        getTime()
        return () => {
            clearInterval(timer)
        }
    }, [])
    /* eslint-disable */
    const getTime = () => {
        timer = setInterval(() => {
            let hours = moment().hours()
            setTime(moment().format('MMMDo dddd HH:mm:ss') + ' 【' + (hours < 2 ? '很晚了早点休息' : hours < 5 ? '适当锻炼可以保证睡眠质量' : hours < 8 ? '早起的鸟儿有虫吃' : hours < 12 ? '早上好' : hours < 14 ? '午休能让下午头脑清醒' : hours < 18 ? '下午好' : hours < 23 ? '晚上好' : '很晚了早点休息') + '】')
        }, 1000)
    }
    /* eslint-disable */
    return (
        <span>{time}</span>
    )
}

export default TimeTitle